<?php
function GetOpenidFromMp($code){
	$url = $this->__CreateOauthUrlForOpenid($code);
	//初始化curl
	$ch = curl_init();
	$curlVersion = curl_version();
	$config = new WxPayConfig();
	$ua = "WXPaySDK/3.0.9 (".PHP_OS.") PHP/".PHP_VERSION." CURL/".$curlVersion['version']." "
	.$config->GetMerchantId();

	//设置超时
	curl_setopt($ch, CURLOPT_TIMEOUT, $this->curl_timeout);
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);
	curl_setopt($ch, CURLOPT_USERAGENT, $ua);
	curl_setopt($ch, CURLOPT_HEADER, FALSE);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

	$proxyHost = "0.0.0.0";
	$proxyPort = 0;
	$config->GetProxy($proxyHost, $proxyPort);
	if($proxyHost != "0.0.0.0" && $proxyPort != 0){
		curl_setopt($ch,CURLOPT_PROXY, $proxyHost);
		curl_setopt($ch,CURLOPT_PROXYPORT, $proxyPort);
	}
	//运行curl，结果以jason形式返回
	$res = curl_exec($ch);
	curl_close($ch);
	//取出openid
	$data = json_decode($res,true);
//		var_dump($data);
	$this->data = $data;
	$openid = $data['openid'];
	return $openid;
}

function ToXml(){
	$xml = "<xml>";
	foreach ($this->values as $key=>$val){
		if (is_numeric($val)){
			$xml.="<".$key.">".$val."</".$key.">";
		}else{
			$xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
		}
    }
    $xml.="</xml>";
    return $xml; 
}
function FromXml($xml){	
    //将XML转为array
    //禁止引用外部xml实体
    libxml_disable_entity_loader(true);
    $arr = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
	return $arr;
}

function curl($url, $str){
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
	//post提交方式
	curl_setopt($ch, CURLOPT_POST, TRUE);
	//全部数据使用HTTP协议中的 "POST" 操作来发送,类似'para1=val1&para2=val2&...'
	curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
	// 抓取URL并把它传递给浏览器
	$res = curl_exec($ch);
	
	// 关闭cURL资源，并且释放系统资源
	curl_close($ch);
	
	$data = json_decode($res,true);
	var_dump($data);


}
//$url = "http://www.wgf.com/post.php";
$url = "https://api.mch.weixin.qq.com/pay/orderquery";
//$str = "a=123&b=456";
curl($url,$str);


?>